#!/usr/bin/env python
# encoding: utf-8
'''
@author: Excelsiorly
@license: (C) Copyright 2022, All Rights Reserved.
@contact: excelsiorly@qq.com
@file: 083. 删除排序链表中的重复元素.py
@time: 2022/1/27 15:02
@desc: https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/
> 给定一个已排序的链表的头 head ， 删除所有重复的元素，使每个元素只出现一次 。返回 已排序的链表 。

@解题思路：
    1. Ot(n), Os(1)
'''

# Definition for singly-linked list.
class ListNode(object):
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next
class Solution(object):
    def deleteDuplicates(self, head):
        """
        :type head: ListNode
        :rtype: ListNode
        """
        def removeNext(node):
            node.next = node.next.next
        if not head: return None
        p = head
        while p:
            while p.next and p.next.val == p.val:
                removeNext(p)
            p = p.next
        return head

if __name__ == '__main__':
    head = ListNode(0, next=ListNode(0, next=ListNode(0, next=ListNode(0))))